<template>
  <div class="transaction-service-list bg-c-fff right-height mb70">
    <p class="bread rel">
      <a href="javascript:void(0);" class="font-s-16">交易监控套餐管理 </a> >
      <a href="javascript:void(0);" class="font-s-14">列表</a>
      <a href="#/index/transaction-new-package">
        <button class="xl-btn-css blue-button abs">新增服务</button>
      </a>
    </p>
    <div class=" content">
      <div class="seach">
        <input type="text" name="" class="input-css" v-model="keyWord" placeholder="监控服务名称/服务编号">
        <button class="xl-btn-css blue-button vb" @click="getTransactionList(1)">搜索</button>
      </div>
      <table width="100%" class="auto">
        <tr>
          <th>交易监控服务名称</th>
          <th>交易次数</th>
          <th>交易有效期</th>
          <th>收费金额</th>
          <th>服务编号</th>
          <th>操作</th>
        </tr>
        <tr v-for="item in transactionList">
          <td>{{item.name}}</td>
          <td>{{item.number|numFilter}}</td>
          <td>{{item.dueTime|dayFilter}}</td>
          <td>{{item.charge | moneyFilter}}</td>
          <td>{{item.innerNo}}</td>
          <td>
            <button class="blue-button small-btn-css" @click="onEdit(item.id)">编辑</button>
            <button class="blue-button small-btn-css" @click="onDelete(item.id)">删除</button>
          </td>
        </tr>
      </table>
      <div class="no-data-tip" v-show="transactionList.length===0">暂无相关数据</div>
      <div class="fix foot-box">
        <pagination :index="pageIndex" :total="pageTotal" v-show="this.transactionList!=0" @pagechange="onPageChange"></pagination>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import Pagination from '../components/Pagination'
export default {
  components: {
    Pagination
  },
  data() {
    return {
      transactionList: [],
      pageIndex: 1,
      pageTotal: 0,
      keyWord: ''
    }
  },
  mounted() {
    this.onPageChange(1)
  },
  methods: {
    onPageChange(n) {
      this.getTransactionList(n)
    },
    getTransactionList(n) {
      this.$http.get('/transactionMonitor/read/list', {
        params: {
          keyWord: this.keyWord
        }
      }).then((data) => {
        if (data.data.httpCode === 200) {
          this.pageIndex = n
          this.pageTotal = Math.ceil(data.data.total / 10)
          this.transactionList = data.data.rows
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    onEdit(id) {
      this.$router.push('/transaction-edit-package' + '?id=' + id)
    },
    onDelete(id) {
      this.$http.delete('/transactionMonitor/delete', {
        params: {
          id: id
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.transactionList.forEach((item, index) => {
            if (item.id === id) {
              this.transactionList.splice(index, 1)
              this.$toasted.show('删除成功')
            }
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络错误')
      })
    }

  },
  filters: {
    moneyFilter(money) {
      return '￥' + (money / 100).toFixed(2) + '元'
    },
    dayFilter(day) {
      if (day <= 0) {
        return '不限时间'
      } else {
        return day + '天'
      }
    },
    numFilter(number) {
      if (number <= 0) {
        return '不限次数'
      } else {
        return number + '次'
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.bread {
  padding-left: 20px;
  border-bottom: 1px solid #ddd;
}

.bread a {
  line-height: 45px;
}

.bread button {
  right: 10px;
  top: 8px;
}

.content {
  padding: 0 35px;
}

.content .seach input,
.content .seach button {
  height: 35px;
  line-height: 35px;
}

.content .seach {
  padding: 20px 0px;
}

.content .seach button {
  margin-left: -5px;
}

.foot-box {
  padding: 35px 0px 0px 0px;
}

.pagination {
  width: auto!important;
  margin: 0 auto!important;
}

</style>
